import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * industryCategory - 国标品类定义 - service
 * @date: 2018-7-24

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel } from 'utils/utils';

function industriesApi(params) {
  return isTenantRoleLevel() ? "".concat(params.tenantId, "/industries") : 'industries';
}
/**
 * 查询一级行业
 * @async
 * @function queryTopCategory
 * @param {object} params - 查询条件
 * @param {?string} params.industryName - 一级行业名称
 * @returns {object} fetch Promise
 */


export function queryTopCategory(_x) {
  return _queryTopCategory.apply(this, arguments);
}
/**
 * 查询二级行业
 * @async
 * @function querySecondCategory
 * @param {object} params - 查询条件
 * @param {!string} params.industryId - 一级行业id
 * @param {?string} params.industryName - 二级行业名称
 * @returns {object} fetch Promise
 */

function _queryTopCategory() {
  _queryTopCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params)), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryTopCategory.apply(this, arguments);
}

export function querySecondCategory(_x2) {
  return _querySecondCategory.apply(this, arguments);
}
/**
 * 查询品类
 * @async
 * @function queryCategory
 * @param {object} params - 查询条件
 * @param {!string} params.industryId - 二级行业id
 * @param {!string} params.categoryName - 品类名称
 * @returns {object} fetch Promise
 */

function _querySecondCategory() {
  _querySecondCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params)), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _querySecondCategory.apply(this, arguments);
}

export function queryCategory(_x3) {
  return _queryCategory.apply(this, arguments);
}
/**
 * 新增行业
 * @async
 * @function saveIndustry
 * @param {object} params.data - 保存数据
 * @param {?string} params.industryId - 一级行业id
 * @param {!string} params.industryCode - 行业编码
 * @param {!string} params.industryName - 行业名称
 * @param {!string} params.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _queryCategory() {
  _queryCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params), "/").concat(params.industryId, "/categories"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryCategory.apply(this, arguments);
}

export function saveIndustry(_x4) {
  return _saveIndustry.apply(this, arguments);
}
/**
 * 新增品类
 * @async
 * @function saveCategory
 * @param {object} params.data - 保存数据
 * @param {?string} params.industryId - 二级行业id
 * @param {!string} params.categoryCode - 品类编码
 * @param {!string} params.categoryName - 品类名称
 * @param {!string} params.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _saveIndustry() {
  _saveIndustry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params)), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _saveIndustry.apply(this, arguments);
}

export function saveCategory(_x5) {
  return _saveCategory.apply(this, arguments);
}
/**
 * 更新行业
 * @async
 * @function putIndustry
 * @param {object} params.data - 保存数据
 * @param {!string} params.industryId - 一级/二级行业id
 * @param {!string} params.industryCode - 行业编码
 * @param {!string} params.industryName - 行业名称
 * @param {!string} params.enabledFlag - 启用标记
 * @param {!string} params.objectVersionNumber - 版本
 * @returns {object} fetch Promise
 */

function _saveCategory() {
  _saveCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params), "/").concat(params.industryId, "/categories"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _saveCategory.apply(this, arguments);
}

export function putIndustry(_x6) {
  return _putIndustry.apply(this, arguments);
}
/**
 * 更新品类
 * @async
 * @function saveCategory
 * @param {object} params.data - 保存数据
 * @param {!string} params.industryId - 二级行业id
 * @param {!string} params.categoryId - 品类id
 * @param {!string} params.categoryCode - 品类编码
 * @param {!string} params.categoryName - 品类名称
 * @param {!string} params.enabledFlag - 启用标记
 * @param {!string} params.objectVersionNumber - 版本
 * @returns {object} fetch Promise
 */

function _putIndustry() {
  _putIndustry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params)), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _putIndustry.apply(this, arguments);
}

export function putCategory(_x7) {
  return _putCategory.apply(this, arguments);
}

function _putCategory() {
  _putCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(industriesApi(params), "/").concat(params.industryId, "/categories"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _putCategory.apply(this, arguments);
}